﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using ExtAspNet;
using FJASPX.Framwork.UI;
using FJASPX.Service;
using FJASPX.Framwork.Helper;
using FJASPX.Framwork.Constant;

namespace PlugNT.Cms.Web.Personal
{
    public partial class Profile: EditPageBase<FJASPX.Domain.User>
    {
        public IUserService iUserService { get; set; }
        #region Property属性
        public override string PowerCode
        {
            get { throw new NotImplementedException(); }
        }
        #endregion
        #region Methods方法
        protected override bool FirstCallRead()
        {
            //初始化控件
            base.FirstCallRead();
            this.IsUpdate = true;
            this.ddl_Trade.Items.Add(new ListItem("--请选择--", "0"));

            this.Model = iUserService.GetUserByName(this.CurrentUser.UserName);
            if (!this.Model.IsNull())
            {
                this.txt_NickName.SetValue(this.Model.NickName);
                this.txt_RealName.SetValue(this.Model.RealName);
                if ("男".Equals(this.Model.Sex))
                {
                    this.txt_Sex.SelectedIndex = 0;
                }
                else
                {
                    this.txt_Sex.SelectedIndex = 1;
                }
                this.txt_Work.SetValue(this.Model.Work);
                this.txt_Mobile.SetValue(this.Model.Mobile);
                this.txt_Telphone.SetValue(this.Model.Phone);
                this.txt_QQ.SetValue(this.Model.QQ);
                this.txt_Email.SetValue(this.Model.Email);
                this.txt_Introduction.SetValue(this.Model.Introduction);
            }
            return true;
        }
        #endregion

        #region Events事件
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            this.Model = iUserService.GetUserByName(this.CurrentUser.UserName);
            try
            {
                this.Model.NickName = this.txt_NickName.GetValue();
                this.Model.RealName = this.txt_RealName.GetValue(); 
                this.Model.Work = this.txt_Work.GetValue();
                this.Model.Mobile = this.txt_Mobile.GetValue();
                this.Model.Phone = this.txt_Telphone.GetValue();
                this.Model.QQ = this.txt_QQ.GetValue();
                this.Model.Email = this.txt_Email.GetValue();
                this.Model.Introduction = this.txt_Introduction.GetValue();

                iUserService.Save(this.Model);
                this.Success(); //这里加清缓存操作
                return;
            }
            catch (Exception ex)
            {
                Log.WriteLog(Message.ERR, ex);
            }
            this.Fail();
        }
        #endregion
    }
}